using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace ServiceImpls
{
    public class SampleServiceImpl : ServiceInterfaces.ISampleService
    {
        #region ISampleService Members

        public NorthwindEntities.Products[] LoadAllProductsByPage(int pageSize, int pageNo)
        {
            try
            {
                return Gateways.Northwind.Select<NorthwindEntities.Products>(pageSize, pageNo);
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "ServiceImpls.SampleServiceImpl"))
                {
                    throw ex;
                }
            }

            return null;
        }

        public TestAccessDbAccessEntities.User[] LoadAllUsers()
        {
            try
            {
                TestAccessDbAccessEntities.User[] users = Gateways.TestAccessDb.SelectAll<TestAccessDbAccessEntities.User>();

                #region Just Test Call Remote Service in Service Impl

                ServiceInterfaces.ISampleService tmp = NBear.IoC.Service.ServiceFactory.Create().GetService<ServiceInterfaces.ISampleService>();
                users[0].Name = tmp.LoadAllProductsByPage(11, 1).Length.ToString() + " results of in-service-impl remote service calling";

                #endregion

                return users;
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "ServiceImpls.SampleServiceImpl"))
                {
                    throw ex;
                }
            }

            return null;
        }

        public int[] aa(int[] objs)
        {
            return objs;
        }

        #endregion
    }
}
